<?php

namespace Modules\Asset\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Validator;
use ThrowException;
use Auth;

class AssetController extends Controller
{
    public function show(Request $req, $assetType)
    {
        $rule = [
        ];

        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $user = Auth::requireLoginUser();

        $res = [];

        if ($assetType === 'money') {

            $asset = $user->asset('money');

            $res = [
                'balance' => $asset->balance,
                'frozen' => $asset->frozen
            ];
        }
        elseif ($assetType === 'redpack') {

            $asset = $user->asset('redpack');

            $res = [
                'balance' => $asset->balance,
                'frozen' => $asset->frozen,
                'withdraw_pending' => $asset->withdraw_records()->status('pending')->sum('value'),
                'withdraw_completed' => $asset->withdraw_records()->status('completed')->sum('value'),
            ];
        }

        return [
            'info' => $res
        ];
    }
}
